package org.example.chain.service.impl;

import org.example.chain.service.Validation;

public class LengthValidation implements Validation {

    private Integer max;
    private Integer min;

    public LengthValidation(Integer min,Integer max) {
        this.min = min;
        this.max = max;
    }

    @Override
    public void valid(String param) throws IllegalArgumentException {
        if (max != null) {
            if (param.length() > max) {
                throw new IllegalArgumentException("长度过长");
            }
        }

        if (min != null) {
            if (param.length() < min) {
                throw new IllegalArgumentException("长度过短");
            }
        }
    }
}
